//
//  HeadSearchTableViewCell.m
//  ChunLaiZhuangClient
//
//  Created by zzs on 16/4/10.
//  Copyright © 2016年 CLZ. All rights reserved.
//

#import "HeadSearchTableViewCell.h"
#import "SearchViewController.h"
@implementation HeadSearchTableViewCell

- (void)awakeFromNib {
    // Initialization code
}
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *identifier = @"HeadSearchTableViewCell";
    // 1.缓存中取
    HeadSearchTableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.创建
    if (cell == nil) {
        cell = [[HeadSearchTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.searchBarView];
        
    }
    return self;
}
-(UIView*)searchBarView{
    if (!_searchBarView) {
        _searchBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 45)];
        _searchBarView.backgroundColor=[UIColor colorWithHexString:@"fafafa"];

        UIButton *searchBt=[UIButton buttonWithType:UIButtonTypeCustom];
        searchBt.frame=CGRectMake(9, 5, SCREEN_WIDTH-18, 34);
        searchBt.layer.cornerRadius=18;
        searchBt.clipsToBounds=YES;
        searchBt.layer.borderColor=[UIColor colorWithHexString:@"d8d8f8"].CGColor;
        searchBt.layer.borderWidth=0.5;
        searchBt.backgroundColor=[UIColor whiteColor];
        UIImageView *searchIcon=[[UIImageView alloc] initWithFrame:CGRectMake(20, 9, 16, 16)];
        searchIcon.image=[UIImage imageNamed:@"icon_search"];
        searchIcon.right=searchBt.width/2-44;
        [searchBt addSubview:searchIcon];
        UILabel* placeHoldLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 2, 200, 30)];
        placeHoldLabel.textColor=[UIColor colorWithHexString:@"c8c8c8"];
        placeHoldLabel.font=[UIFont systemFontOfSize:12];
        placeHoldLabel.left=searchIcon.right+7;
        placeHoldLabel.text=@"输入商品名或品牌名";
        [searchBt addSubview:placeHoldLabel];
        [searchBt addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventTouchUpInside];
        [_searchBarView addSubview:searchBt];
    }
    return _searchBarView;
}
-(void)searchAction:(UIButton*)bt{
    SearchViewController *searchVC=[[SearchViewController alloc] init];
    UIViewController *currentVC=[HeadSearchTableViewCell viewController:self];
    [currentVC.navigationController pushViewController:searchVC animated:NO];
}
@end
